using System.Collections.ObjectModel;
using HMCollada.Core;
using HMCollada.FX;
using System.Xml;

namespace HMCollada.FX {
    internal struct HMColladaLibraryMaterials {
        internal string id;
        internal string name;
        internal HMColladaAsset asset;
        internal Collection<HMColladaMaterial> material;
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        internal static HMColladaLibraryMaterials LoadLibraryMaterials() {
            HMColladaLibraryMaterials newLibraryMaterials = new HMColladaLibraryMaterials();
            newLibraryMaterials.id = colladaReader.GetAttribute("id");
            newLibraryMaterials.name = colladaReader.GetAttribute("name");

            newLibraryMaterials.material = new Collection<HMColladaMaterial>();

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "asset": newLibraryMaterials.asset = LoadAsset(); break;
                        case "material": newLibraryMaterials.material.Add(LoadMaterial()); break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "library_materials");

            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newLibraryMaterials;
        }
    }
}